﻿using System;
using System.Runtime.Serialization;

namespace IntoNails.Models
{
    [Serializable]
    public class Order : ISerializable
    {
        #region Constructors

        protected Order()
        {
        }

        public Order(SerializationInfo info, StreamingContext context)
        {
            this.UniqueCode = (Guid)info.GetValue("UniqueCode", typeof (Guid));
            this.ReportedBy = (Guid)info.GetValue("ReportedBy", typeof(Guid));
            this.TotalAmmount = info.GetDouble("TotalAmmount");
            this.CreatedDate = info.GetDateTime("CreatedDate");
            this.UpdatedDate = info.GetDateTime("UpdatedDate");
            this.Notes = info.GetString("Notes");
            this.IsValid = info.GetBoolean("IsValid");
        }

        #endregion

        #region Properties

        public Guid UniqueCode { get; set; }
        public Guid ReportedBy { get; set; }
        public double TotalAmmount { get; set; }

        public DateTime CreatedDate { get; set; }
        public DateTime UpdatedDate { get; set; }

        public string Notes { get; set; }

        public bool IsValid { get; set; }

        #endregion

        public static Order CreateNewOrder()
        {
            return new Order();
        }

        public static Order CreateOrder(Guid reportedStaffCode, double totalAmmount, string notes)
        {
            return new Order
                       {
                           UniqueCode = Guid.NewGuid(),
                           ReportedBy = reportedStaffCode,
                           TotalAmmount = totalAmmount,
                           Notes = notes,
                           CreatedDate = DateTime.Today,
                           UpdatedDate = DateTime.Today,
                           IsValid = true
                       };
        }

        #region Implementation of ISerializable

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("UniqueCode", this.UniqueCode);
            info.AddValue("ReportedBy", this.ReportedBy);
            info.AddValue("TotalAmmount", this.TotalAmmount);
            info.AddValue("Notes", this.Notes);
            info.AddValue("CreatedDate", this.CreatedDate);
            info.AddValue("UpdatedDate", this.UpdatedDate);
            info.AddValue("IsValid", this.IsValid);
        }

        #endregion
    }
}
